<?php

class Controllers_Soumission extends RestController {
    public function get() {
        $this->response = array('TestResponse' => null);
        $this->responseStatus = 501;
    }

    public function post() {
        require_once("Config/connexion.php");
        
        require_once("Fonctions/authentification.php");
        require_once("Fonctions/soumissions.php");
        
        $params = $this->request['params'];
        
        $responseStatus = 200;
        $responseText = "";
        
        $authok = estAuthentifie($params["userid"], $params["authkey"]);
        
        if ($authok) {
            $villeDejaValidee = villeDejaValidee($params["userid"], $params["city_postal_code"],$params["city_name"], $params["country_name"]);
            
            if (!$villeDejaValidee) {
                $retour = ajoutScore($params["userid"], $params["city_postal_code"], $params["city_name"], $params["country_name"]);
                $responseText = $retour;
            }
            else {
                $responseStatus = 403;
                $responseText = "Ville deja validee";
            }
        }
        else {
            $responseText = "Auth pas ok";
            $responseStatus = 403;
        }
        
        $this->response = array('Response' => $responseText);
        $this->responseStatus = $responseStatus;
    }
    public function put() {
            $this->response = array('TestResponse' => null);
            $this->responseStatus = 501;
    }

    public function delete() {
            $this->response = array('TestResponse' => null);
            $this->responseStatus = 501;
    }
}